home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
- <!-- Group books by whether the title contains given key words -->
- <xsl:key name="book-group" match="book" use="number(contains(title,'XSL')) * 3"/>
- <xsl:key name="book-group" match="book" use="number(contains(title,'ASP')) * 2"/>
- <xsl:key name="book-group" match="book" use="number(contains(title,'Java')) * 1"/>
- <xsl:key name="book-no-group" match="book" use="number(contains(title,'XSL')) + number(contains(title,'ASP')) + number(contains(title,'Java'))"/>
-
- <xsl:template match="/">
- <html>
- <head>
- <title>Books by interest priority</title>
- </head>
- <body>
- <xsl:call-template name="book-table">
- <xsl:with-param name="title">Books about XSL</xsl:with-param>
- <xsl:with-param name="book-group">book-group</xsl:with-param>
- <xsl:with-param name="book-group-id">3</xsl:with-param>
- </xsl:call-template>
- <xsl:call-template name="book-table">
- <xsl:with-param name="title">Books about ASP</xsl:with-param>
- <xsl:with-param name="book-group">book-group</xsl:with-param>
- <xsl:with-param name="book-group-id">2</xsl:with-param>
- </xsl:call-template>
- <xsl:call-template name="book-table">
- <xsl:with-param name="title">Books about Java</xsl:with-param>
- <xsl:with-param name="book-group">book-group</xsl:with-param>
- <xsl:with-param name="book-group-id">1</xsl:with-param>
- </xsl:call-template>
- <xsl:call-template name="book-table"/>
- </body>
- </html>
- </xsl:template>
-
- <xsl:template match="book">
- <tr>
- <td><xsl:value-of select="title"/></td>
- <td><xsl:value-of select="author"/></td>
- <td><xsl:value-of select="@isbn"/></td>
- <!-- show position of element in original xml -->
- <td align="right"><xsl:value-of select="count(preceding-sibling::book)+1"/></td>
- </tr>
- </xsl:template>
-
- <xsl:template name="book-table">
- <xsl:param name="title" select="'Other Books'"/>
- <xsl:param name="book-group" select="'book-no-group'"/>
- <xsl:param name="book-group-id" select="number(0)"/>
- <h3><xsl:value-of select="$title"/></h3>
- <table border="1" width="100%">
- <tr>
- <th width="60%">Title</th>
- <th width="25%">Author</th>
- <th>ISBN</th>
- <th>Item No.</th>
- </tr>
- <xsl:apply-templates select="key($book-group,$book-group-id)">
- <xsl:sort select="title"/>
- </xsl:apply-templates>
- </table>
- </xsl:template>
-
- </xsl:stylesheet>